﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.DemandPlan
{
    public partial class BidResultEdit : System.Web.UI.Page
    {
        Maticsoft.BLL.supplier_bidplan_order sbom = new Maticsoft.BLL.supplier_bidplan_order(); 
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int dpid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(dpid);
                    BindDDL(dpid);
                }
            }
        }

        //增加中标公司排名
        protected void lbn_addpm_Click(object sender, EventArgs e)
        {
            string zbbh = this.txt_zbbh.Text;
            string wtgs = this.txt_wtgsmc.Text;
            string zbgs = this.txt_zbgsmc.Text;
            string pbrq = this.txt_rq.Text;
            string sid = this.ddl_zbgs.SelectedValue;
            string sname = this.ddl_zbgs.SelectedItem.Text;
            string proid = this.lbl_proid.Text;
            string projectname = this.lbl_projectname.Text;
            int dpid = 0;
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                dpid = (Convert.ToInt32(Request.Params["id"]));
            }

            string score = this.txt_df.Text;
            string bj = this.txt_bj.Text;
            string pw = this.txt_pw.Text;
            string jdr = this.txt_jdr.Text;
            string s_order = this.txt_pm.Text;
            string bagnum = this.lbl_bagnum.Text;
            string bagname = this.lbl_bagname.Text;

            if (string.IsNullOrEmpty(pbrq))
            {
                Maticsoft.Common.MessageBox.Show(this.Page,"请选择中标日期！");
                return;
            }

            Maticsoft.Model.supplier_bidplan_order sbo = new Maticsoft.Model.supplier_bidplan_order();

            sbo.zbbh = zbbh;
            sbo.wtgs = wtgs;
            sbo.zbgs = zbgs;
            sbo.pbrq = DateTime.Parse(pbrq);
            sbo.sid = int.Parse(sid);
            sbo.proid = proid;
            sbo.dpid = dpid;
            sbo.score = score;
            sbo.bj = bj;
            sbo.pw = pw;
            sbo.jdr = jdr;
            sbo.s_order = int.Parse(s_order);
            sbo.sname = sname;
            sbo.projectname = projectname;
            sbo.bagname = bagname;
            sbo.bagnum = bagnum;

            List<Maticsoft.Model.supplier_bidplan_order> li_sbo = null;

            if (Session["supplier_bidplan_order"] != null)
            {
                li_sbo = Session["supplier_bidplan_order"] as List<Maticsoft.Model.supplier_bidplan_order>;
            }
            else
            {
                li_sbo = new List<Maticsoft.Model.supplier_bidplan_order>();
                Session["supplier_bidplan_order"] = li_sbo;
            }

            li_sbo.Add(sbo);

            this.GridView1.DataSource = li_sbo;
            this.GridView1.DataBind();


        }
        //显示信息
        private void ShowInfo(int dpid)
        {
            DataSet ds = new lcs.BLL.demandplaninfo().GetList(" and dpid="+dpid);

            if (ds.Tables[0].Rows.Count == 1)
            {
                this.lbl_bagname.Text = ds.Tables[0].Rows[0]["bagname"].ToString();
                this.lbl_projectname.Text = ds.Tables[0].Rows[0]["projectName"].ToString();
                this.lbl_proid.Text = ds.Tables[0].Rows[0]["proid"].ToString();
                this.lbl_bagnum.Text = ds.Tables[0].Rows[0]["bagnum"].ToString();
            }
            
        }

        private void BindDDL(int dpid)
        {
            DataSet ds = new Maticsoft.BLL.supplier_bidplan().GetListByView(" dpid=" + dpid 
                +" and isBidFee= 1 and isBidDeposit=1 and isSendBidPlan=1 ");

            this.ddl_zbgs.DataSource = ds;
            this.ddl_zbgs.DataTextField = "sname";
            this.ddl_zbgs.DataValueField = "supplier_id";
            this.ddl_zbgs.DataBind();
        }
        //重置排名
        protected void lbn_re_Click(object sender, EventArgs e)
        {
            Session["supplier_bidplan_order"] = null;
            List<Maticsoft.Model.supplier_bidplan_order> li_sbo = new List<Maticsoft.Model.supplier_bidplan_order>();

            this.GridView1.DataSource = li_sbo;
            this.GridView1.DataBind();


        }

        //
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            if (Session["supplier_bidplan_order"] != null)
            {
                Response.Redirect("BidResultSubmit.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this.Page, "请增加中标厂商排名信息");
            }
        }
    }
}